package sk.tramtatiri.pages.users;

import java.util.List;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.basic.MultiLineLabel;
import org.apache.wicket.model.Model;
import org.apache.wicket.spring.injection.annot.SpringBean;
import sk.tramtatiri.MySession;
import sk.tramtatiri.core.IConstants;
import sk.tramtatiri.data.dao.interfaces.SportDao;
import sk.tramtatiri.data.dataobjects.Sport;

/**
 * 
 * 
 * @author nue
 *
 */
public class SportsPage extends UserPageTemplate {
	
	@SpringBean
	private SportDao sportDao;
	
	private MultiLineLabel labelSports;
	
	public SportsPage() {
		CollapsibleBorder borderCreate = new CollapsibleBorder("borderCreateSport", new Model("Vytvorit sport"), new Model("Vytvorit sport"));
		SportCreatePanel sportCreatePanel = new SportCreatePanel("sportCreatePanel");
		
		if (((MySession)getSession()).hasPermission()) {
			borderCreate.setVisible(true);
		} else {
			borderCreate.setVisible(false);
		}
		
		borderCreate.add(sportCreatePanel);
		add(borderCreate);
		printSportsToPage(); 
	}
	
	
	@Override
	public String getPageTitle() {
		return IConstants.PAGE_NAME+" - Sporty";
	}
	
	/**
	 * print all sports to console
	 */
	public void printSportsToConsole() {
		List<Sport> sportList = sportDao.findAll();
		for(int i=0;i<sportList.size();i++) {
			Sport sport = sportList.get(i);
			System.out.println((i+1)+". "+sport.getName()+" "+sport.getCalories());
		}
	}
	
	/**
	 * print all sports to page
	 */
	public void printSportsToPage() {
		StringBuilder sportString = new StringBuilder();
		List<Sport> sportList = sportDao.findAll();
		for(int i=0;i<sportList.size();i++) {
			Sport sport = sportList.get(i);
			sportString.append((i+1)+". "+sport.getName()+" "+sport.getCalories()+"\n");
		}
		labelSports = new MultiLineLabel("printAllSports",sportString.toString());
		this.add(labelSports);
	}

}
